package dmas.lab.models;

import java.util.ArrayList;
import java.util.List;

import dmas.lab.FileReader;

public class Group {

	private List<Contact> members;

	private String groupName;
	private static Group group;

	public Group(String groupName) {
		this.groupName = groupName;
		members = new ArrayList<Contact>();
	}

	public List<Contact> getMembers() {
		return members;
	}
	
	/***
	 * Return null if contact was not found
	 * @param contactID
	 * @return
	 */
	public Contact getContact(int contactID){
		for (Contact contact : members) {
			if(contact.getID() == contactID){
				return contact;
			}
		}
		return null;
	}

	public int getSize(){
		return members.size();
	}
	public boolean addMember(Contact contact) {
		return members.add(contact);
	}

	public boolean deleteMember(Contact contact) {
		return members.remove(contact);
	}

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String name) {
		this.groupName = name;
	}

	public static Group getGroup() {
		if (group == null) {
			group = new Group("Facebook Group");
			List<Contact> readContacts = FileReader.readContacts();
			for (Contact contact : readContacts) {
				group.addMember(contact);
			}
		}
		return group;
	}
}
